home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_cups.idb / usr / freeware / etc / cups / install-cups.z / install-cups
Text File  |  2002-04-08  |  5KB  |  186 lines

  1. #!/bin/sh
  2. #Tag 0x00000610
  3. #
  4. # Author: Andrea Suatoni
  5. #
  6. # $Id: install-cups,v 1.1.1.1 2002/02/01 03:31:12 and Exp $
  7. #
  8.  
  9. FREEWARE_DIR="/usr/freeware"
  10. CUPS_BIN_FILES="/usr/bin/cancel /usr/bin/disable /usr/bin/enable /usr/bin/lp /usr/bin/lpstat /usr/bsd/lpq /usr/bsd/lpr /usr/bsd/lprm"
  11. CUPS_SBIN_FILES="/usr/etc/lpc /usr/lib/accept /usr/lib/lpadmin /usr/lib/reject"
  12. CUPS_BACKUP_EXT=".cups_backup"
  13.  
  14. #
  15. # Checks that we are the super-user
  16. #
  17. CheckPermission() {
  18.   cid=`/usr/bin/id | /usr/bin/nawk '{print substr($1,index($1,"("))}'`;
  19.   if [ "$cid" != "(root)" ]; then
  20.     echo "You must be logged in as root to use this program."
  21.     exit 1;
  22.   fi
  23. }
  24.  
  25. #
  26. # Backup the IRIX binary passed as first parameter, and create symbolic link to
  27. # the CUPS binary passed as the second parameter
  28. #
  29. InstallCUPSFile() {
  30.   if [ \( -f $1 \) -a \( ! -l $1 \) -a \( -f $1$CUPS_BACKUP_EXT \) ]; then
  31.     echo "Fatal error: $1 is not linked to CUPS, but has already been backuped by CUPS"
  32.     exit 1
  33.   fi
  34.   if [ \( -l $1 \) -a \( -f $1$CUPS_BACKUP_EXT \) ]; then
  35.     echo "$1: already linked to CUPS"
  36.     return 0
  37.   fi
  38.   if [ ! -f $1 ]; then
  39.     /sbin/touch $1
  40.   fi
  41.   /sbin/mv $1 $1$CUPS_BACKUP_EXT
  42.   /sbin/ln -s $2 $1
  43. }
  44.  
  45. #
  46. # Remove the symbolic link to the CUPS binary and restore the original
  47. # IRIX binary (if this last one has zero lenght, it is a dummy placeholder
  48. # created during the CUPS installation and must be removed as well)
  49. #
  50. UninstallCUPSFile() {
  51.   if [ ! -f $1$CUPS_BACKUP_EXT ]; then
  52.     return 0
  53.   fi
  54.   /sbin/rm -f $1
  55.   if [ -s $1$CUPS_BACKUP_EXT ]; then
  56.     /sbin/mv $1$CUPS_BACKUP_EXT $1
  57.   else
  58.     /sbin/rm -f $1$CUPS_BACKUP_EXT
  59.   fi
  60. }
  61.  
  62. #
  63. # Switch from IRIX to CUPS spooling system
  64. #
  65. InstallCUPS() {
  66.   echo ""
  67.   echo "================================="
  68.   echo "CUPS spooling system installation"
  69.   echo "================================="
  70.   echo ""
  71.   echo "The following IRIX system files will be backuped and a symbolic link"
  72.   echo "to the equivalent CUPS binary will be created in their place:"
  73.   echo ""
  74.   for f in $CUPS_BIN_FILES; do
  75.     cupsfile=$FREEWARE_DIR/bin/`basename $f`
  76.     echo "$f\t-> $cupsfile"
  77.   done
  78.   for f in $CUPS_SBIN_FILES; do
  79.     cupsfile=$FREEWARE_DIR/sbin/`basename $f`
  80.     echo "$f\t-> $cupsfile"
  81.   done
  82.   echo ""
  83.   echo "WARNING\07: Running this script you will modify the behaviour of the default IRIX"
  84.   echo "         spooling system, which will be switched to CUPS. Also, the default"
  85.   echo "         IRIX printer spooler lpsched(1M) will be stopped and disabled from"
  86.   echo "         automatic system startup. It is advisable that before running this"
  87.   echo "         script you will remove any defined printer from the IRIX spooling"
  88.   echo "         system. Do not mix IRIX and CUPS printers!"
  89.   echo ""
  90.   echo "Are you sure you wish to continue? (y/n) [n]: \c"
  91.   read yn
  92.   if [ \( "$yn" != "y" \) -a \( "$yn" != "Y" \) ]; then
  93.     exit 1
  94.   fi
  95.   for f in $CUPS_BIN_FILES; do
  96.     cupsfile=$FREEWARE_DIR/bin/`basename $f`
  97.     InstallCUPSFile $f $cupsfile
  98.   done
  99.   for f in $CUPS_SBIN_FILES; do
  100.     cupsfile=$FREEWARE_DIR/sbin/`basename $f`
  101.     InstallCUPSFile $f $cupsfile
  102.   done
  103.  
  104.   #
  105.   # Disable the IRIX printing scheduler
  106.   #
  107.   [ -x /usr/lib/lpshut ] && /usr/lib/lpshut > /dev/null 2>&1
  108.   /sbin/chkconfig lp off > /dev/null 2>&1
  109.  
  110.   #
  111.   # Enable the CUPS printing scheduler
  112.   #
  113.   /sbin/chkconfig cups on > /dev/null 2>&1
  114.  
  115.   echo ""
  116.   echo "The CUPS spooling system has been successfully installed."
  117.   echo ""
  118.   echo "VERY IMPORTANT\07: Please remember to switch back to the IRIX spooling system"
  119.   echo "                before installing IRIX overlays or upgrades, before removing"
  120.   echo "                IRIX spooling system, or before removing or upgrading CUPS!"
  121.   echo "                (use '`dirname $prog`/uninstall-cups' to do it)"
  122. }
  123.  
  124. #
  125. # Switch from CUPS to IRIX spooling system
  126. #
  127. UninstallCUPS() {
  128.   echo ""
  129.   echo "==================================="
  130.   echo "CUPS spooling system uninstallation"
  131.   echo "==================================="
  132.   echo ""
  133.   echo "The default spooling system will be switched back to the IRIX one."
  134.   echo "The symbolic links to CUPS binaries will be removed and the IRIX binaries"
  135.   echo "will be restored."
  136.   echo ""
  137.   echo "Are you sure you wish to continue? (y/n) [n]: \c"
  138.   read yn
  139.   if [ \( "$yn" != "y" \) -a \( "$yn" != "Y" \) ]; then
  140.     exit 1
  141.   fi
  142.   for f in $CUPS_BIN_FILES; do
  143.     UninstallCUPSFile $f
  144.   done
  145.   for f in $CUPS_SBIN_FILES; do
  146.     UninstallCUPSFile $f
  147.   done
  148.  
  149.   #
  150.   # Disable the CUPS printing scheduler
  151.   #
  152.   [ -x /etc/init.d/cups ] && /etc/init.d/cups stop > /dev/null 2>&1
  153.   /sbin/chkconfig cups off > /dev/null 2>&1
  154.  
  155.   #
  156.   # Enable the IRIX printing scheduler
  157.   #
  158.   /sbin/chkconfig lp on > /dev/null 2>&1
  159.   echo ""
  160.   echo "The IRIX spooling system has been successfully restored."
  161. }
  162.  
  163. #########################################################################
  164. #
  165. # Main program
  166. #
  167.  
  168. #
  169. # Ensure that we are root
  170. #
  171. CheckPermission
  172.  
  173. #
  174. # See how we have been called (install or uninstall?)
  175. #
  176. prog=$0
  177. op=`basename $prog`
  178. case $op in
  179.   install-cups)
  180.     InstallCUPS
  181.     ;;
  182.   uninstall-cups)
  183.     UninstallCUPS
  184.     ;;
  185. esac
  186.